package com.yoomiito.app.pay

import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.model.order.OrderingInfo
import com.yoomiito.app.utils.AllCode
import com.yoomiito.app.utils.Type

class PayUtilsManager() {

    companion object{
        val instance by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            PayUtilsManager()
        }
    }

    private var context: BaseActivity<*>?=null
    private var goodsType:Int = -1
    lateinit var payResultListener: (PayResult) -> Unit

    fun init(context: BaseActivity<*>,goodsType:Int):PayUtilsManager{
        this.context = context
        this.goodsType = goodsType
        return this
    }

    /**
     * 普通支付
     */
    fun toGeneralPay(orderPayInfo: OrderPayInfo):PayUtilsManager{
        if (context==null)return this
        if (goodsType==-1)return this
        when(goodsType){
            Type.GoodsType.GiveMore->context?.let { GeneralPayUtils(it,payResultListener).showPayDialog(orderPayInfo) }
        }
        return this
    }

    /**
     * 星店支付
     */
    fun toStarStorePay(orderingInfo: OrderingInfo):PayUtilsManager{
        if (context==null)return this
        if (goodsType==-1)return this

        when(goodsType){
            AllCode.StarStore->{
                StarStorePayUtils(context,payResultListener).showPayDialog(orderingInfo)
            }
        }
        return this
    }

    fun release(){
        context = null
        goodsType = -1
        payResultListener = {}
    }

}